﻿using System;
using System.Collections.Generic;

using HL.Core.Models;

namespace HL.Lib.Models
{
    public class ModNewsPropertyEntity : EntityBase
    {
        
        #region Autogen by HL

        [DataInfo]
        public override int ID { get; set; }

        [DataInfo]
        public int MenuID { get; set; }

        [DataInfo]
        public int NewsID { get; set; }

        [DataInfo]
        public int PropertyID { get; set; }

        [DataInfo]
        public int PropertyValueID { get; set; }

        #endregion      
  
        private WebMenuEntity _oMenu = null;
        public WebMenuEntity getMenu()
        {
            if (_oMenu == null && MenuID > 0)
                _oMenu = WebMenuService.Instance.GetByID_Cache(MenuID);

            if (_oMenu == null)
                _oMenu = new WebMenuEntity();

            return _oMenu;
        }      
  
        private ModNewsEntity _oProduct = null;
        public ModNewsEntity getProduct()
        {
            if (_oProduct == null && NewsID > 0)
                _oProduct = ModNewsService.Instance.GetByID(NewsID);

            if (_oProduct == null)
                _oProduct = new ModNewsEntity();

            return _oProduct;
        }      
  
        private ModPropertyEntity _oProperty = null;
        public ModPropertyEntity getProperty()
        {
            if (_oProperty == null && PropertyID > 0)
                _oProperty = ModPropertyService.Instance.GetByID(PropertyID);

            if (_oProperty == null)
                _oProperty = new ModPropertyEntity();

            return _oProperty;
        }

        private ModPropertyEntity _oPropertyValue = null;
        public ModPropertyEntity getPropertyValue()
        {
            if (_oPropertyValue == null && PropertyValueID > 0)
                _oPropertyValue = ModPropertyService.Instance.GetByID(PropertyValueID);

            if (_oPropertyValue == null)
                _oPropertyValue = new ModPropertyEntity();

            return _oPropertyValue;
        }

    }

    public class ModNewsPropertyService : ServiceBase<ModNewsPropertyEntity>
    {

        #region Autogen by HL

        private ModNewsPropertyService()
            : base("[Mod_NewsProperty]")
        {

        }

        private static ModNewsPropertyService _Instance = null;
        public static ModNewsPropertyService Instance
        {
            get
            {
                if (_Instance == null)
                    _Instance = new ModNewsPropertyService();

                return _Instance;
            }
        }

        #endregion

        public ModNewsPropertyEntity GetByID(int id)
        {
            return base.CreateQuery()
               .Where(o => o.ID == id)
               .ToSingle();
        }

    }
}